/*
提交链接:https://leetcode.cn/problems/top-k-frequent-elements/
347. 前 K 个高频元素
赖德檀 2024/12/19
*/

class Solution {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        unordered_map<int,int>mp;
        priority_queue<int>qe;
        vector<int>arr;
        for(auto i : nums) mp[i]++;
        for(auto it : mp)
        {
            qe.push(it.second);
        }
        while(!qe.empty()&&k--)
        {
            for(auto& it :mp)
            {
                if(it.second==qe.top())
                {
                    // cout<<it.first<<" "<<it.second<<endl;
                    arr.push_back(it.first);
                    it.second=-2;
                    break;
                }
            }
            qe.pop();
        }
        return arr;
    }
};